home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wlib11_2.zip / EXAMPLES.EXE / EXAM80.C < prev    next >
Text File  |  1991-03-23  |  3KB  |  101 lines

  1.   #include <stdio.h>
  2.   #include <string.h>
  3.   #include "window.h"
  4.  
  5.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  6.  
  7.                     /* define filename characters */
  8.   #define FILENAMECHARS  "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
  9.  
  10.   VWPOINTER vw;          /* virtual window pointer */
  11.   WPOINTER w;            /* Window pointer */
  12.   char filename[26];
  13.   FILE *infile;          /* input file handle */
  14.  
  15.   main()
  16.   {
  17.     unsigned int i,j,row,col;
  18.     WindowInitializeSystem();
  19.     WindowSaveInitial(0);
  20.     /* set up a Type 0 virtual window */
  21.     vw = VirtualInitialize(NOATTRIBUTE,  /* virtual window type number */
  22.                            200,      /* Number of rows */
  23.                            80,      /* Number of cols */
  24.                            0);      /* Attribute      */
  25.  
  26.     /* set up viewport window */
  27.     w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
  28.     WindowOpen(w);
  29.     WindowDisplay(w,1,NOEFFECT);
  30.  
  31.     /* read a file name */
  32.     read_file();
  33.  
  34.     /* display file in viewport */
  35.     WindowAssignToVirtual(w,vw,1,1);      /* Assign viewport to virtual window */
  36.     flush_keyboard_flag = TRUE;        /* Set keyboard flush to TRUE */
  37.     while (1)
  38.     {
  39.       switch (GET_KEY())    /* Keep getting keys until ESCAPE key is hit */
  40.       {
  41.          case UARROW:      /* Move viewport up 1 line */
  42.            WindowScrollViewport(w,1,UP);
  43.          break;
  44.          case DARROW:      /* Move viewport down 1 line */
  45.            WindowScrollViewport(w,1,DOWN);
  46.          break;
  47.          case LARROW:      /* Move viewport left 1 line */
  48.            WindowScrollViewport(w,1,LEFT);
  49.          break;
  50.          case RARROW:      /* Move viewport right 1 line */
  51.            WindowScrollViewport(w,1,RIGHT);
  52.          break;
  53.          case ESC:         /* End program */
  54.            close_all();
  55.          break;
  56.       }
  57.     }
  58.   }
  59.  
  60.   read_file()         /* Gets a filename and displays it in the window */
  61.   {
  62.      int ch;
  63.      unsigned r = 1, c = 1;
  64.      filename[0]=0;
  65.      WindowWriteString(w,"Please enter a file name: ",1,1);
  66.      WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
  67.      if ((infile = fopen(filename,"r")) == NULL)
  68.      {
  69.        WindowMoveCursor(w,3,1);
  70.        WindowPrintf(w,"File name %s does not exist\nPress a key to continue",
  71.                 filename);
  72.        GET_KEY();
  73.        close_all();
  74.      }
  75.      else
  76.      while(1)         /* Read characters into virtual window */
  77.      {
  78.        ch = fgetc(infile);
  79.        if (feof(infile))
  80.          break;
  81.        if (ch != '\n')
  82.          VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
  83.  
  84.        else
  85.        {
  86.          r++;
  87.          c=1;
  88.  
  89.        }
  90.      }
  91.      fclose(infile);
  92.   }
  93.  
  94.  
  95.  
  96.   close_all()
  97.   {
  98.     WindowClose(w,NOEFFECT);
  99.     exit(0);
  100.   }
  101.